<template>
  <div v-if="hasValue" class="rating-display">
    <el-rate :model-value="rounded" disabled :allow-half="true" :max="5" :size="props.size || 'small'" />
    <span class="rating-text">{{ formatted }}</span>
  </div>
  <span v-else class="rating-placeholder">-</span>
</template>

<script setup lang="ts">
import { computed } from 'vue'

const props = defineProps<{
  value?: number | null
  size?: 'large' | 'default' | 'small'
}>()

const round1 = (v?: number | null) => {
  if (v === undefined || v === null || isNaN(Number(v))) return 0
  return Math.round(Number(v) * 10) / 10
}

const hasValue = computed(() => props.value !== undefined && props.value !== null && !isNaN(Number(props.value)))
const rounded = computed(() => round1(props.value))
const formatted = computed(() => (hasValue.value ? round1(props.value).toFixed(1) : '-'))
</script>

<style scoped>
.rating-display {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rating-placeholder {
  color: #999;
}
</style>


